package retrospection.电话号码的字母组合;

import java.util.ArrayList;
import java.util.List;

public class Solution {

    public List<String> letterCombinations(String digits) {
        if(digits.equals("")){
            return new ArrayList<String>();
        }
        String[] dict = new String[]{"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        ArrayList<String> ans = new ArrayList<>();
        retrospection(dict, digits, new StringBuffer(""), 0, ans);
        return ans;
    }

    public void retrospection(String[] dict, String digits, StringBuffer temp, int index, List<String> ans) {
        if (temp.length() == digits.length()) {
            if (!temp.equals("")){
                ans.add(new String(temp));
            }
            return;
        }
        char c = digits.charAt(index);
        String s = dict[c - '0'];
        for (int i = 0; i < s.length(); i++) {
            temp.append(s.charAt(i));
            retrospection(dict, digits, temp, index + 1, ans);
            temp.deleteCharAt(temp.length() - 1);
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution().letterCombinations(""));
    }


}
